﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>单据打印</title>
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/jquery-1.7.2.min.js"></script>
    <!-- 导入配置文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script type="text/javascript">

        var printType = 0;
        var isFrameCross = GetQueryString("isFrameCross");
        $(function () {

            $("#Msg").html("<h3>正在加载请稍候....</h3>");

            var fk_bill = GetQueryString("FK_Bill");
            var nodeID = GetQueryString("FK_Node");
            var workID = GetQueryString("WorkID");
            var flowNo = GetQueryString("FK_Flow");
            var fid = GetQueryString("FID");
            printType = GetQueryString("PrintType");
            //初始化页面信息
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("PrintDoc_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
            if (data.indexOf("info@") == 0) {
                data = data.replace("info@", "");
                data = JSON.parse(data);
                if (data.length == 0) {
                    alert("没有绑定表单，无需打印");
                    return;
                }
                var html = "";
                html += "<fieldset>";
                html += "<legend>ND" + GetQueryString("FK_Node") + "绑定的表单</legend>";
                html += "<ul>";

                for (var i = 0; i < data.length; i++) {
                    if (data[i].FrmType == 3) //url
                        continue;
                    html += "<li><a href='javaScript:void(0)' target=_blank onclick=PrintSignleFormIt(" + flowNo + "," + nodeID + "," + workID + "," + fid + ",\"" + data[i].No + "\")>" + data[i].Name + "</a></li>";
                }
                html += "<li>说明：点击上面的表单名称进行RTF进行打印</li>";
                html += "</ul>";
                html += "</fieldset>";

                document.getElementById("Msg").innerHTML = html;
                return;
            }


            //如果是一个url.
            if (data.indexOf('url@') == 0) {

                data = data.replace('url@', '');
                if (data.indexOf('rtf@') != -1) {
                    window.location.href = data.replace('rtf@', '');
                } else {
                    data = data.replace('word@', '');
                    if (plant == 'CCFlow') {
                        data += ",WSUrl=http://" + window.location.host + "/WF/CCForm/CCFormAPI.asmx";
                    }
                    if (plant == "JFlow") {
                        alert('还没有翻译.');
                        return;
                    }


                    WinOpen(data);
                }
                return;
            }

            //如果包含多个打印模板
            var ens = JSON.parse(data);

            var html = "<ul>";
            for (var i = 0; i < ens.length; i++) {
                var en = ens[i];
                //  html += "<li ><a href='?FK_Bill=" + en.No + "&FK_Flow=" + flowNo + "&FK_Node=" + nodeID + "&WorkID=" + workID + "'>" + en.Name + "</li>";
                html += "<li><a href='javascript:void(0);' onclick=PrintIt(" + en.No + "," + flowNo + "," + nodeID + "," + workID + "," + fid + ",\"" + en.FK_MapData + "\",\"" + en.TemplateFileModel + "\") >" + en.Name + "</li>";
            }

            html += "</ul>";

            $("#Msg").html(html);

        });

        function PrintSignleFormIt(flowNo, nodeId, WorkID,FID,ccfromId) {
            $("#rtf").html("");
            var ens = new Entities("BP.WF.Template.BillTemplates");
            ens.Retrieve("FK_MapData", ccfromId);
            if (ens.length == 0){
                alert("当前节点上没有绑定单据模板");
                return false;
             }
            if (ens.length == 1) {
                PrintIt(ens[0].No, flowNo, nodeId, WorkID, FID, ccfromId);
                return;
             }

            var html = "<ul>";
            for (var i = 0; i < ens.length; i++) {
                var en = ens[i];
                //  html += "<li ><a href='?FK_Bill=" + en.No + "&FK_Flow=" + flowNo + "&FK_Node=" + nodeID + "&WorkID=" + workID + "'>" + en.Name + "</li>";
                html += "<li><a href='javascript:void(0);' onclick=PrintIt(" + en.No + "," + flowNo + "," + nodeId + "," + WorkID + "," + FID + ",\"" + ccfromId + "\",\""+en.TemplateFileModel+"\") >" + en.Name + "</li>";
            }

            html += "</ul>";
            $("#rtf").html(html);

        }

        //打印.
        function PrintIt(billNo, flowNo, nodeID, workID, FID, ccfromId,printModal) {

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddPara("FK_Bill", billNo);
            handler.AddPara("FK_Flow", flowNo);
            handler.AddPara("FK_Node", nodeID);
            handler.AddPara("WorkID", workID);
            handler.AddPara("FID", FID);
            handler.AddPara("CCFormID", ccfromId);

            var data = handler.DoMethodReturnString("PrintDoc_Done");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
            //如果是一个url.
            if (data.indexOf('url@') == 0) {

                data = data.replace('url@', '');
                if (data.indexOf('rtf@') != -1) {
                    window.location.href = data.replace('rtf@', '');
                } else {
                    data = data.replace('word@', '');
                    if (plant == 'CCFlow' && printModal == 1) {
                        data += "?WSUrl=http://" + window.location.host + "/WF/CCForm/CCFormAPI.asmx";
                    }
                    if (plant == "JFlow") {
                        alert('还没有翻译.');
                        return;
                    }
                    WinOpen(data);
                    return;

                }
            }
            
        }

        //取消退回
        function Close() {
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.returnWorkWindowClose("取消");
                }
               
            } else {
                ChildrenPostMessage("取消", "returnWorkWindowClose");
            }
           
        }
      
    </script>
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="Msg">
    </div>
    <div id="rtf"></div>
    <center>
        <input type="button" value='关闭' onclick="window.close();" />
    </center>
</body>
</html>
